#include<iostream>
#include <string>
#include <queue>
using namespace std;
int main(){
    priority_queue<int,vector<int>,greater<int> >l;
    int n,a;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a;
        l.push(a);
    }
    int sum=0;
    while(l.size()!=1){
        int x=l.top();
        l.pop();
        int y=l.top();
        l.pop();
        sum+=x+y;
        l.push(x+y);
    }
    printf("%d\n",sum);
    return 0;
}
